<?php
namespace Admin\Controller;
use Think\Controller;
use Common\Controller\AuthController;

class AccountController extends Controller {
	public function index(){
		$user = D("Account");
		$list = $user->select();
		$this->assign('list',$list);
		$this->display();
	}
	public function add(){
		if(IS_POST){
			$user = D('User');
			$data['username'] = $_POST['username'];
			$data['password'] = md5($_POST['password']);
			if($user->create($data)){
				$result = $user->add();
			}
			//$auth_group_access = M('auth_group_access')->add(array('uid'=>$result,'group_id'=>3));
			if($result){
				$uid = M('user')->where(array('username'=>$_POST['username']))->getField('id');
				$auth_group_access = M('auth_group_access')->add(array('uid'=>$uid,'group_id'=>3));
				$this->success("添加成功","index");
			}else{
				$this->error("添加失败");
			}
		}else{
			$this->display();
		}
	}
	public function delete(){
		$where['id'] = I('id');
		$result = M('Account')->where($where)->delete();
		if($result){
			M('auth_group_access')->where(array('uid'=>$where['id']))->delete();
			$this->success("删除成功",U("Account/index"));
		}else{
			$this->error("删除失败");
		} 
	}

}